var express = require('express');
var app = express();
//var multer = require('multer');
//var upload = multer({dest:'./images'});
var multiparty = require('multiparty');
var fs = require('fs');




app.use(express.static(__dirname));
app.post('/file', function(req, res,next){
    var form = new multiparty.Form({uploadDir: './images'});
    form.parse(req, function (err, fileds, files) {
        var filesTmp = JSON.stringify(files, null, 2);
        console.log(files);
        var inputFile =files.file[0];
        var uploadedPath = inputFile.path;
        var dstPath = './images/' + inputFile.originalFilename;
        //重命名为真实文件名
        fs.rename(uploadedPath, dstPath, function (err) {
            if (err) {
                console.log('rename error: ' + err);
            } else {
                console.log(dstPath);
                console.log('rename ok');
            }
        });
    })
});

app.listen(3000);